package com.ruiyu.setting

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.util.xmlb.XmlSerializerUtil

@State(name = "KivensJson2DartSettings", storages = [(Storage("KivensJson2DartSettings.xml"))])
data class Settings(
    var modelSuffix: String,
    var isOpenNullSafety: Boolean?,
    var isOpenNullAble: Boolean?
) : PersistentStateComponent<Settings> {

    companion object {
        fun instance(): Settings {
            return ApplicationManager.getApplication().getService(Settings::class.java) ?: Settings()
        }
    }

    constructor() : this(
        "entity", null, null
    )

    override fun getState(): Settings {
        return this
    }

    override fun loadState(state: Settings) {
        XmlSerializerUtil.copyBean(state, this)
    }
}